package com.ruoyi.merchant.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.LaunchPage;
import com.ruoyi.merchant.service.ILaunchPageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 启动页配置Controller
 * 
 * @author chengxin.ju
 * @date 2023-12-07
 */
@Slf4j
@RestController
@RequestMapping("/page")
public class LaunchPageController extends BaseController
{
    @Autowired
    private ILaunchPageService launchPageService;

    /**
     * 查询启动页配置列表
     */
//    @RequiresPermissions("merchant:page:list")
    @GetMapping("/list")
    public List<LaunchPage> list(LaunchPage launchPage)
    {
        List<LaunchPage> list = new ArrayList<>();
        try {
            launchPage.setDel(0);
            list = launchPageService.selectLaunchPageList(launchPage);
        }catch (Exception ex){
            log.error(ex.getMessage(),ex);
        }
        return list;
    }

    /**
     * 导出启动页配置列表
     */
    @RequiresPermissions("merchant:page:export")
    @Log(title = "启动页配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LaunchPage launchPage)
    {
        List<LaunchPage> list = launchPageService.selectLaunchPageList(launchPage);
        ExcelUtil<LaunchPage> util = new ExcelUtil<LaunchPage>(LaunchPage.class);
        util.exportExcel(response, list, "启动页配置数据");
    }

    /**
     * 获取启动页配置详细信息
     */
    @RequiresPermissions("merchant:page:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(launchPageService.selectLaunchPageById(id));
    }

    /**
     * 新增启动页配置
     */
    @RequiresPermissions("merchant:page:add")
    @Log(title = "启动页配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LaunchPage launchPage)
    {
        return toAjax(launchPageService.insertLaunchPage(launchPage));
    }

    /**
     * 修改启动页配置
     */
    @RequiresPermissions("merchant:page:edit")
    @Log(title = "启动页配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LaunchPage launchPage)
    {
        return toAjax(launchPageService.updateLaunchPage(launchPage));
    }

    /**
     * 删除启动页配置
     */
    @RequiresPermissions("merchant:page:remove")
    @Log(title = "启动页配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(launchPageService.deleteLaunchPageByIds(ids));
    }
}
